package com.distributer.report.domain.statistics.model;

import java.math.BigDecimal;

import com.distributer.report.domain.common.Entry;
import com.distributer.report.domain.statistics.valueobj.OrderValueObj;

/**
 * 统计产品的订单总数，总金额
 * @author xiaolin           
 *
 */
public class OrderStatistics extends Entry{
	
	private static final long serialVersionUID = -7903073927273031882L;

	private Integer waitPayOrderCount;
	
	private Integer alreadyPayOderCount;
	
	private Integer refundOrderCount;
	
	private String waitPayOrderPremium;
	
	private String alreadyPayOderPremium;
	
	private String refundOrderPremium;

	public OrderStatistics(){
		super();
		init();
	}
	
	private void init(){
		this.waitPayOrderCount = 0;
		this.alreadyPayOderCount = 0;
		this.refundOrderCount = 0;
		this.waitPayOrderPremium = "0";
		this.alreadyPayOderPremium = "0";
		this.refundOrderPremium = "0";
	}

	public Integer getWaitPayOrderCount() {
		return waitPayOrderCount;
	}

	public void setWaitPayOrderCount(Integer waitPayOrderCount) {
		this.waitPayOrderCount = waitPayOrderCount;
	}

	public Integer getAlreadyPayOderCount() {
		return alreadyPayOderCount;
	}

	public void setAlreadyPayOderCount(Integer alreadyPayOderCount) {
		this.alreadyPayOderCount = alreadyPayOderCount;
	}

	public Integer getRefundOrderCount() {
		return refundOrderCount;
	}

	public void setRefundOrderCount(Integer refundOrderCount) {
		this.refundOrderCount = refundOrderCount;
	}

	public String getWaitPayOrderPremium() {
		return waitPayOrderPremium;
	}

	public void setWaitPayOrderPremium(String waitPayOrderPremium) {
		this.waitPayOrderPremium = waitPayOrderPremium;
	}

	public String getAlreadyPayOderPremium() {
		return alreadyPayOderPremium;
	}

	public void setAlreadyPayOderPremium(String alreadyPayOderPremium) {
		this.alreadyPayOderPremium = alreadyPayOderPremium;
	}

	public String getRefundOrderPremium() {
		return refundOrderPremium;
	}

	public void setRefundOrderPremium(String refundOrderPremium) {
		this.refundOrderPremium = refundOrderPremium;
	}
	
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}
	
	@Override
	public int hashCode() {
		return super.hashCode();
	}
	
	//private static final Logger LOGGER = LoggerFactory.getLogger(OrderStatistics.class);
	
	/**
	 * 订单统计
	 * @param orderValueObj 被统计订单对象
	 */
	public void statistics(OrderValueObj orderValueObj){
		//LOGGER.info("orderValueObj info => "+ JSONObject.toJSONString(orderValueObj));
		if (orderValueObj.isWaitPay()) {
			//LOGGER.info("orderNo: "+orderValueObj.getOrderNo()+" isWaitPay");
			waitPayStatistics(orderValueObj);
		}
		if (orderValueObj.isAlreadyPay()) {
			//LOGGER.info("orderNo: "+orderValueObj.getOrderNo()+" isAlreadyPay");
			alreadyPayStatistics(orderValueObj);
		}
		if (orderValueObj.isRefundPay()) {
			//LOGGER.info("orderNo: "+orderValueObj.getOrderNo()+" isRefundPay");
			refundPayStatistics(orderValueObj);
		}
	}
	
	private void waitPayStatistics(OrderValueObj orderValueObj){
		this.waitPayOrderCount = this.waitPayOrderCount + 1;
		this.waitPayOrderPremium = new BigDecimal(this.waitPayOrderPremium).add(new BigDecimal(orderValueObj.getOrderPremium())).toString();
	}
	
	private void alreadyPayStatistics(OrderValueObj orderValueObj){
		this.waitPayOrderCount = this.waitPayOrderCount - 1;
		this.waitPayOrderPremium = new BigDecimal(this.waitPayOrderPremium).subtract(new BigDecimal(orderValueObj.getOrderPremium())).toString();
		this.alreadyPayOderCount = this.alreadyPayOderCount + 1;
		this.alreadyPayOderPremium = new BigDecimal(this.alreadyPayOderPremium).add(new BigDecimal(orderValueObj.getOrderPremium())).toString();
	}
	
	private void refundPayStatistics(OrderValueObj orderValueObj){
		this.refundOrderCount = this.refundOrderCount + 1;
		this.refundOrderPremium = new BigDecimal(this.refundOrderPremium).add(new BigDecimal(orderValueObj.getOrderPremium())).toString();
	}
}
